<template>
	<view class="wrap">
		<u-waterfall v-model="flowList" ref="uWaterfall">
			<template v-slot:left="{leftList}">
				<view class="demo-warter" v-for="(item, index) in leftList" :key="index" @tap='jump("../detail/detail"+"?price=",item.title,item.price)'>
					<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
					<u-lazy-load :height="height" threshold="-300" border-radius="10" :image="item.image" :index="index"></u-lazy-load>
					<view class="demo-info">
						<u-image  width="100rpx" height="100rpx" :src="item.avatar" shape="circle"  :fade="true" duration="450">{{item.avatar}}</u-image>
						<text>甜甜</text>
					</view>
					<view class="demo-title">
						{{item.title}}
					</view>
					<view class="demo-price">
						{{item.price}}币/局
					</view>
					<view class="demo-tag">
						<view class="demo-tag-owner">
							绝地求生
						</view>
						<view class="demo-tag-text">
							英雄联盟1
						</view>
					</view>
					<view class="demo-num">
						{{item.num}}
					</view>
					
					<!-- <u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close" @click="remove(item.id)"></u-icon> -->
				</view>
			</template>
			<template v-slot:right="{rightList}">
				<view class="demo-warter" v-for="(item, index) in rightList" :key="index" @tap='jump("../detail/detail"+"?price=",item.title,item.price)'>
					<u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load>
					<view class="demo-info">
						<u-image  width="100rpx" height="100rpx" :src="item.avatar" shape="circle"  :fade="true" duration="450">{{item.avatar}}</u-image>
						<text>甜甜</text>
					</view>
					<view class="demo-title">
						{{item.title}}
					</view>
					<view class="demo-price">
						{{item.price}}币/局
					</view>
					<view class="demo-tag">
						<view class="demo-tag-owner">
							绝地求生
						</view>
						<view class="demo-tag-text">
							英雄联盟1
						</view>
					</view>
					<view class="demo-num">
						{{item.num}}
					</view>
					
					<!-- <u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close" @click="remove(item.id)"></u-icon> -->
				</view>
			</template>
		</u-waterfall>
		<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="addRandomData"></u-loadmore>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadStatus: 'loadmore',
				flowList: [],
				title:'',
				height:'300',
				list:  [
					{
						avatar:'http://cdn1.98gamesy.com/%E5%AE%A3%E4%BC%A0/%E4%BA%BA%E7%89%A9%E5%A5%B33/%E5%A4%B4%E5%83%8F/32ca577cf02bf6209143c71eee16b094.jpg',
						price: 2,
						title: '可甜可盐，技术好不粘人',
						num: '989人下单',
						image: 'http://cdn1.98gamesy.com/%E5%AE%A3%E4%BC%A0/%E4%BA%BA%E7%89%A9%E5%A5%B31/5e84a46fc9163aca1d56b1ec5ef579a6.jpg',
						
					},
					{
						avatar:'http://cdn1.98gamesy.com/%E5%AE%A3%E4%BC%A0/%E4%BA%BA%E7%89%A9%E5%A5%B33/%E5%A4%B4%E5%83%8F/32ca577cf02bf6209143c71eee16b094.jpg',
						price: 3,
						title: '可甜可盐，技术好不粘人',
						num: '989人下单',
						image: 'http://cdn1.98gamesy.com/%E5%AE%A3%E4%BC%A0/%E4%BA%BA%E7%89%A9%E5%A5%B31/5e84a46fc9163aca1d56b1ec5ef579a6.jpg',
					},
					{
						avatar:'http://cdn1.98gamesy.com/%E5%AE%A3%E4%BC%A0/%E4%BA%BA%E7%89%A9%E5%A5%B33/%E5%A4%B4%E5%83%8F/32ca577cf02bf6209143c71eee16b094.jpg',
						price: 4,
						title: '可甜可盐，技术好不粘人',
						num: '989人下单',
						image: 'http://cdn1.98gamesy.com/%E5%AE%A3%E4%BC%A0/%E4%BA%BA%E7%89%A9%E5%A5%B31/5e84a46fc9163aca1d56b1ec5ef579a6.jpg',
					},
					
				]
			}
		},
		onLoad() {
			this.addRandomData();
			wx.setNavigationBarTitle({
				title:'点陪玩'
			});
		},
		onReachBottom() {
			this.loadStatus = 'loading';
			// 模拟数据加载
			setTimeout(() => {
				this.addRandomData();
				this.loadStatus = 'loadmore';
			}, 1000)
		},
		methods: {
			addRandomData() {
				for(let i = 0; i < 10; i++) {
					let index = this.$u.random(0, this.list.length - 1);
					// 先转成字符串再转成对象，避免数组对象引用导致数据混乱
					let item = JSON.parse(JSON.stringify(this.list[index]))
					item.id = this.$u.guid();
					this.flowList.push(item);
				}
			},
			remove(id) {
				this.$refs.uWaterfall.remove(id);
			},
			jump(path,title,price){
				uni.navigateTo({
				    url: path+price+"&title="+title
				});
			}
		}
	}
</script>

<style>
	/* page不能写带scope的style标签中，否则无效 */
	page {
		background-color: rgb(240, 240, 240);
	}
</style>

<style lang="scss" scoped>
	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 8px;
		position: relative;
	}
	
	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}
	.demo-info {
		width: 100%;
		height: 100rpx;
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}
	.demo-image {
		width: 100%;
		border-radius: 4px;
	}
	
	.demo-title {
		font-size: 30rpx;
		margin-top: 5px;
		color: $u-main-color;
	}
	
	.demo-tag {
		display: flex;
		margin-top: 5px;
	}
	
	.demo-tag-owner {
		background-color: $u-type-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}
	
	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}
	
	.demo-price {
		font-size: 30rpx;
		color: $u-type-error;
		margin-top: 5px;
	}
	.demo-num{
		color: $u-tips-color;
		margin-top: 5px;
		font-size: 14px;
	}
</style>